<?php
/**
 * 
 * 
 * @version $Id: WeiboView.php 8 2012-08-31 08:11:17Z linsir123 $
 */
class WeiboView
{
	/**
	 * @var 相对路径
	 */
	static $domain;
	
	/**
	 * @var Css集合
	 */
	static $css;
	
	/**
	 * @var Javascript集合
	 */
	static $js;
	
	/**
	 * 初始化
	 */
	static function init()
	{
		static $__init = false;
		if ($__init) {
			return ;
		}
		$__init = true;
		
		///
		$view = App::getView();
		$engine = & $view->engine;
		
		self::$css = array();
		self::$js = array();
		self::$domain = App::getRequest()->domain;
		
		/// 函数
		$engine->registerPlugin('function', 'JS', 			array('WeiboView', 'sDomJs'));
		$engine->registerPlugin('function', 'CSS', 			array('WeiboView', 'sDomCss'));
	}
	
	/**
	 * Css
	 */
	static function sDomCss($params = null)
	{
		$layout = intval($params['layout']);
		if (empty($layout)) 
			$layout = 2;
			
		self::$css[0] = sprintf(self::$css[0], $layout);
		
		///
		if (strlen(self::$domain)==1) 
			$b = '';
		else {
			$b = substr(self::$domain, 1);
			$b = substr($b, 0, strlen($b)-1);
			$b = 'b='.$b.'&amp;';
		}
		$content = '<link type="text/css" rel="stylesheet" href="';
		$content .= self::$domain.'min/'.$b.'f='.implode(',', self::$css);
		$content .= '?version=2.0" />';
		return $content;
	}
	
	/**
	 * Javascript
	 */
	static function sDomJs($params = null)
	{
		/*$content = '<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.6.2/jquery.min.js"></script>';
		$content .= "\r\n";*/
		$content .= '<script type="text/javascript">if(!window.jQuery){document.write(\'<script type="text/javascript" src="'.self::$domain.'javascript/jquery-1.6.2.min.js"><\/script>\');}</script>';
		$content .= "\r\n";
		
		///
		$content .= '<script type="text/javascript" src="';
		$content .= self::$domain.'min/b='.substr(self::$domain, 1).'javascript&amp;f='.implode(',', self::$js);
		$content .= '"></script>';
		///
		
		return $content;
	}
}
